<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="lib/vue.js"></script>
</head>
<body>
  <div id="root">
    <h1>App</h1>
    <my-layout></my-layout>
  </div>
</body>
<template id="main">
  <div>
    <h6>main</h6>
    {{ msg }} - {{ num }}
  </div>
</template>
<template id="layout">
  <div>
    <h2>Layout</h2>
    <my-main></my-main>
  </div>
</template>
<script>
  const myMain = {
    template: '#main',
    inject: ['msg', 'num']
  }
  const myLayout = {
    template: '#layout',
    components: {
      myMain
    }
  }
  new Vue({
    el: '#root',
    data: {
      num: 10000
    },
    components: {
      myLayout
    },
    // provide: {
    //   msg: 'hello',
    //   num: this.num
    // }

    // 有变量时
    provide () { // 传递的是当前组件的变量
      return {
        msg: 'hello',
        num: this.num
      }
    }
  })
</script>
</html>